<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <title>Vue.set 的使用</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        姓名：{{ person.name }} <br>
        年龄：{{ person.age }} <br>
        性别：{{ person.gender }} <br>
        <button @click="addGender">添加一个性别属性，默认值是男</button>
    </div>

    <script>
        new Vue({
            el: '#app',
            data: {
                person: { name: '张三', age: 18 }
            },
            methods: {
                addGender() {
                    // this.person.gender = '男'
                    // Vue.set(this.person, 'gender', '男')
                    this.$set(this.person, 'gender', '男')
                }
            }
        })
    </script>
</body>
</html>